#lang racket

(define (sort ord seq)
  (if (null? seq)
      '()
      (let ((pivot (car seq)))
        (let ((less (lambda (x) (ord x pivot)))
              (greater (lambda (x) (not (ord x pivot)))))
          (let ((left-part (sort ord (filter less (cdr seq))))
                (right-part (sort ord (filter greater (cdr seq)))))
            (append left-part (list pivot) right-part))))))

(sort (lambda (x y) (< (car x) (car y))) (list (cons 10 9) (cons 8 7) (cons 6 5) (cons 4 3) (cons 2 1)))

(sort < (list 10 9 8 7 6 5 4 3 2 1))
